home *** CD-ROM | disk | FTP | other *** search
- Path: news.voicenet.com!news
- From: kobak@voicenet.com (Peter Kobak)
- Newsgroups: comp.lang.c++
- Subject: Re: Hints on program optimization needed
- Date: 21 Feb 1996 23:52:38 GMT
- Organization: Voicenet - Internet Access - (215)674-9290
- Message-ID: <4ggb86$65m@news.voicenet.com>
- NNTP-Posting-Host: ivyland357.voicenet.com
- X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
-
- In message <3126ec6c.6806559@nntp.ix.netcom.com> - BHaddock@ix.netcom.com
- (Brian F. Haddock) writes:
- :>
- :>I'm interested in any hints/tips you could provide on program
- :>optimization. Nothing real fancy, just simple little 'tricks' that
- :>enhance program performance.
- :>
- :>For instance, what's more efficient - a if/then/else construct or a
- :>select/case? How about virtual functions? You get the picture.
-
- At the risk of sounding like a wise guy, program optimization is best
- accomplished through the use of appropriate algorithms, a smart compiler, and
- then examination of the slowest parts of the code. You will (usually) gain
- almost nothing by universally applying "rules" about language facilities.
-
- Code it in the most straightforward, natural way possible. Then, find the
- slow parts. Change the algorithm so you get better performance at the risk
- of worse space and complexity - by far the biggest gains to be had in most
- non-trivial programs are algorithm changes. Only at the very end of the
- process, when you're sure you've squeezed everything out of your code
- structure and only a few dozen lines take the bulk of your time, should you
- consider choices like if() versus switch().
-
- Since I don't want to seem like a total jerk, to answer your 2 specific
- examples:
-
- if() versus switch() - depends on implementation. Except for special cases in
- some compilers, there's very little difference, and it can't be generalized.
-
- virtual functions - one additional level of indirection; that is a couple of
- machine ops adding up to 5-20 clocks (< 1 micro second).
-
- ================
- Peter Kobak
- kobak@voicenet.com
-
-
-